package com.nest.WorkNest.api;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.nest.WorkNest.config.UserInfo;
import com.nest.WorkNest.entity.AddShoppingCart;
import com.nest.WorkNest.entity.AddressInfo;
import com.nest.WorkNest.entity.NewBulkOrder;
import com.nest.WorkNest.entity.PaymentInfo;
import com.nest.WorkNest.entity.User;
import com.nest.WorkNest.tools.FileHelper;
import com.nest.WorkNest.tools.PhoneHelper;
import com.orhanobut.logger.Logger;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by chenchuan on 2015/8/13 0013.
 * 除新建询价单，新建制版打样单与上传图片的post请求都在这儿
 * 自动实现异步处理
 *
 */
public class XutilsPost {
    /**
     * 发送请求
     *
     * @param context
     * @param url
     * @param params
     * @param iOAuthCallBack
     */

    public void doPost(final Context context, String url, RequestParams params, final IOAuthCallBack iOAuthCallBack) {

        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000 * 10);
        http.send(HttpRequest.HttpMethod.POST, url, params, new RequestCallBack<String>() {

            @Override
            public void onFailure(HttpException httpException, String result) {
                Toast.makeText(context, "网络请求超时，请检查您的网络。", Toast.LENGTH_SHORT).show();
                iOAuthCallBack.getDealException(httpException, result);
            }

            @Override
            public void onSuccess(ResponseInfo<String> info) {
                iOAuthCallBack.getIOAuthCallBack(info.result);
            }

            @Override
            public void onLoading(long total, long current, boolean isUploading) {
                iOAuthCallBack.getLoadingCallBack(total, current, isUploading);
            }
        });
    }

    /**
     * 开发单详情
     *
     * @param context
     * @param needId
     * @param iOAuthCallBack
     */
    public void doPostNeedDetail(Context context, String needId, IOAuthCallBack iOAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("needId", needId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryNeedDetail, params, iOAuthCallBack);
    }

    /**
     * 开发单列表
     *
     * @param context
     * @param iOAuthCallBack
     */
    public void doPostNeedList(Context context, IOAuthCallBack iOAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "0");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryNeedRecords, params, iOAuthCallBack);
    }

    public void doPostLogin(Context context, User user, IOAuthCallBack iOAuthCallBack) {
        String cid = FileHelper.getShareProf(context, UserInfo.CID, UserInfo.CID);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("systemId", Api.systemId);
            json.put("userName", user.getTelPhone());
            json.put("password", user.getPassword());
//            json.put("userName", "gckj");
//            json.put("password", "123456");
            json.put("deviceId", PhoneHelper.OS());
            json.put("deviceId", cid);
            json.put("type", "android");
            params.addBodyParameter("data", json.toString());
            Logger.json(json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.userLogin, params, iOAuthCallBack);
    }

    public void doPostQuoDetail(Context context, String quotationID, IOAuthCallBack iOAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("quoteId", quotationID);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryQuoteDetail, params, iOAuthCallBack);
    }

    public void doPostEnquiry(Context context, IOAuthCallBack iOAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "0");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryInquireRecords, params, iOAuthCallBack);
    }

    public void doPostEnquiryDetail(Context context, String inquireId, IOAuthCallBack iOAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("inquireId", inquireId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryInquireDetail, params, iOAuthCallBack);
    }

    public void doPostAddressList(Context context, String addressId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            if (!TextUtils.isEmpty(addressId)) {
                json.put("addressId", addressId);
            }
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryAddressList, params, ioAuthCallBack);
    }

    public void doPostAddaddress(Context context, AddressInfo addressInfo, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("addressId", addressInfo.getAddressId());
            json.put("name", addressInfo.getName());
            json.put("cellPhone", addressInfo.getCellPhone());
            json.put("address", addressInfo.getAddress());
            json.put("gender", "");
            json.put("province", addressInfo.getProvince());
            json.put("city", addressInfo.getCity());
            json.put("District", "");
            json.put("Street", "");
            json.put("postCard", addressInfo.getPostCard());
            json.put("type", addressInfo.getType());
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.updateAddress, params, ioAuthCallBack);
    }

    public void doPostProductType(Context context, String fatherType, IOAuthCallBack ioAuthCallBack) {
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("systemId", Api.systemId);
            json.put("devicesId", PhoneHelper.OS());
            if (!TextUtils.isEmpty(fatherType)) {
                json.put("fatherType", fatherType);
            }
            params.addBodyParameter("data", json.toString());
            Logger.d(Api.queryProductType + "?data=" + json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryProductType, params, ioAuthCallBack);
    }

    public void doPostProductStyle(Context context, IOAuthCallBack ioAuthCallBack) {
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("systemId", Api.systemId);
            json.put("devicesId", PhoneHelper.OS());
            json.put("fatherType", "1");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryProductStyle, params, ioAuthCallBack);
    }

    public void doPostBulkorderRecords1(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "1");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryBulkorderRecords, params, ioAuthCallBack);
    }

    public void doPostBulkorderRecords2(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "2");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryBulkorderRecords, params, ioAuthCallBack);
    }

    public void doPostBulkorderRecords3(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "3");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryBulkorderRecords, params, ioAuthCallBack);
    }

    public void doPostBulkorderDetail(Context context, String bulkOrderId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("bulkOrderId", bulkOrderId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryBulkorderDetail, params, ioAuthCallBack);
    }

    public void doPostFavorite(Context context, String productId, String type, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("productId", productId);
            json.put("type", type);
            params.addBodyParameter("data", json.toString());
            Logger.json(json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.productCollect, params, ioAuthCallBack);
    }

    public void doPostProductSelectRecords(Context context, String type, String productType, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        params.setContentType(Api.APPLICATION_WWW);
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", type);
            json.put("productType", productType);
            json.put("productStyle", "");
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.productSelectRecords, params, ioAuthCallBack);
    }

    public void doPostLogout(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.userLogout, params, ioAuthCallBack);
    }

    public void doPostUserDetail(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryUserDetail, params, ioAuthCallBack);
    }

    public void doPostStatus(Context context, String bulkOrderId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("orderId", bulkOrderId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryOrderStatusRecords, params, ioAuthCallBack);
    }

    public void doPostDelivery(Context context, String bulkOrderId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("orderId", bulkOrderId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryOrderDeliveryRecords, params, ioAuthCallBack);
    }

    public void doPostProductDetail(Context context, String productId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("productId", productId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryProductDetail, params, ioAuthCallBack);
    }

    public void doPostShoppingCart(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryShoppingCartList, params, ioAuthCallBack);
    }

    public void doPostBulkOrder(Context context, NewBulkOrder newBulkOrder, ArrayList<HashMap<String, String>> datalist, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        JSONArray array = new JSONArray();
        JSONObject main = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("productId", newBulkOrder.getProductId());
            json.put("productName", newBulkOrder.getProductName());
            json.put("productType", newBulkOrder.getProductType());
            for (int i = 0; i < datalist.size(); i++) {
                JSONObject data = new JSONObject();
                data.put("color", datalist.get(i).get("color"));
                data.put("size", datalist.get(i).get("size"));
                data.put("quantity", datalist.get(i).get("number"));
                array.put(data);
            }
            json.put("totalQuantity", newBulkOrder.getTotalQuantity());
            json.put("perPrice", newBulkOrder.getPerPrice());
            json.put("totalPrice", newBulkOrder.getTotalPrice());
            json.put("requiredExplain", newBulkOrder.getRequiredExplain());
            json.put("userReceiveAddress", newBulkOrder.getUserReceiveAddress());
            json.put("userCellPhone", newBulkOrder.getUserCellPhone());
            json.put("deliveryTime", newBulkOrder.getDeliveryTime());
            json.put("deliveryWay", newBulkOrder.getDeliveryWay());
            main.put("userName", userName);
            main.put("token", Token);
            main.put("SCRecord", json);
            main.put("dataList", array);
            Logger.d(Api.bulkorder + "?data=" + main.toString());
            params.addBodyParameter("data", main.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.bulkorder, params, ioAuthCallBack);
    }

    public void doPostAddShoppingCart(Context context, AddShoppingCart addShoppingCart, String Type, ArrayList<HashMap<String, String>> dataList, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        JSONObject main = new JSONObject();
        JSONArray array = new JSONArray();
        RequestParams params = new RequestParams();
        try {
            main.put("userName", userName);
            main.put("token", Token);
            if (!Type.equals("1")) {
                json.put("id", addShoppingCart.getId());
            }
            for (int i = 0; i < dataList.size(); i++) {
                JSONObject data = new JSONObject();
                data.put("color", dataList.get(i).get("color"));
                data.put("size", dataList.get(i).get("size"));
                data.put("quantity", dataList.get(i).get("number"));
                array.put(data);
            }
            json.put("productId", addShoppingCart.getProductId());
            json.put("productName", addShoppingCart.getProductName());
            json.put("totalQuantity", addShoppingCart.getTotalQuantity());
            json.put("perPrice", addShoppingCart.getPerPrice());
            json.put("totalPrice", addShoppingCart.getTotalPrice());
            json.put("requiredExplain", addShoppingCart.getRequiredExplain());
            json.put("deliveryTime", addShoppingCart.getDeliveryTime());
            json.put("deliveryWay", addShoppingCart.getDeliveryWay());
            json.put("userReceiveAddress", addShoppingCart.getAddressId());
            main.put("SCRecord", json);
            main.put("dataList", array);
            params.addBodyParameter("data", main.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.addShoppingCart, params, ioAuthCallBack);
    }

    public void doPostDelShoppingCart(Context context, String id, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        JSONObject json2 = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", "0");
            json2.put("id", id);
            json.put("SCRecord", json2);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.addShoppingCart, params, ioAuthCallBack);
    }

    public void doPostPay(Context context, PaymentInfo paymentInfo, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("orderId", paymentInfo.getOrderId());
            json.put("paySerialNumber", paymentInfo.getPaySerialNumber());
            json.put("payContent", paymentInfo.getPayContent());
            json.put("payUserName", paymentInfo.getPayUserName());
            json.put("paySum", Float.valueOf(paymentInfo.getPaySum()));
            json.put("payTime", paymentInfo.getPayTime());
            json.put("payAccount", paymentInfo.getPayAccount());
            json.put("toPayId", paymentInfo.getToPayId());
            json.put("collectionUserName", paymentInfo.getCollectionUserName());
            json.put("collectionAccount", paymentInfo.getCollectionAccount());
            json.put("remark", paymentInfo.getRemark());
            json.put("payExplains", "");
            json.put("paySum1", paymentInfo.getPaySum1());
            params.addBodyParameter("data", json.toString());
            Logger.json(json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.pay, params, ioAuthCallBack);
    }

    public void doPostqueryToPayRecords(Context context, String toPayId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            if (TextUtils.isEmpty(toPayId)) {
                json.put("type", "0");
            } else {
                json.put("toPayId", toPayId);
            }
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryToPayRecords, params, ioAuthCallBack);
    }

    public void doPostApply(Context context, String type, String percentage, String describe, String productId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", type);
            json.put("productId", productId);
            json.put("percentage", percentage);
            json.put("describe", describe);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.productApply, params, ioAuthCallBack);
    }

    public void doPostUnApply(Context context, String type, String productId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("type", type);
            json.put("productId", productId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.productApply, params, ioAuthCallBack);
    }

    public void doPostinquireDevelop(Context context, String inquireId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("inquireId", inquireId);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.inquireDevelop, params, ioAuthCallBack);
    }


    public void doPostUpfile(Context context, String filePath, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        RequestParams imgParam = new RequestParams();
        JSONObject json = new JSONObject();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            imgParam.addBodyParameter("data", json.toString());
            imgParam.addBodyParameter("filedata", new File(filePath));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.fileUpload, imgParam, ioAuthCallBack);
    }

    /**
     * 购物车列表
     *
     * @param context
     * @param id
     * @param ioAuthCallBack
     */
    public void doPostqueryShoppingCartRecords(Context context, String id, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("shoppingcartId", id);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.queryShoppingCartRecords, params, ioAuthCallBack);
    }

    public void doPostupdateUserInfo(Context context, HashMap<String, String> user, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("nickName", user.get("nickname"));
            json.put("realName", user.get("myname"));
            json.put("introduction", user.get("intro"));
            json.put("email", user.get("email"));
            json.put("payAccount", user.get("payway"));
            json.put("identificationNumber", user.get("idnum"));
            json.put("firmName", user.get("companyname"));
            json.put("storeAddressLink", user.get("storelink"));
            json.put("cellPhone", user.get("phone"));
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPost(context, Api.updateUserInfo, params, ioAuthCallBack);
    }

    public void doPostSubmit(Context context, String orderId, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            json.put("orderId", orderId);
            params.addBodyParameter("data", json.toString());
            Logger.d(Api.needConfirm + "?data=" + json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.needConfirm, params, ioAuthCallBack);
    }

    public void doPostgetSendMessage(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.getSendMessage, params, ioAuthCallBack);
    }

    public void doPostgetMymessage(Context context, IOAuthCallBack ioAuthCallBack) {
        String userName = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TEL_PHONE);
        String Token = FileHelper.getShareProf(context, UserInfo.USER_INFO, UserInfo.TOKEN);
        JSONObject json = new JSONObject();
        RequestParams params = new RequestParams();
        try {
            json.put("userName", userName);
            json.put("token", Token);
            params.addBodyParameter("data", json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        doPost(context, Api.getMyMessage, params, ioAuthCallBack);
    }

    public interface IOAuthCallBack {
        void getIOAuthCallBack(String result);

        void getDealException(HttpException httpException, String result);

        void getLoadingCallBack(long total, long current, boolean isUploading);
    }
}

